extends Node2D

const BRICK := preload("res://Scenes/Stage/stage_organ/brick.tscn")

@export var generate_force:float
@export var generate_max_count: int

var generate_count: int = 0

func _on_button_pressed() -> void:
	if generate_count < generate_max_count:
		generate_count += 1
		if Global.current_stage_name != "stage5":
			generate()
		else:
			await get_tree().create_timer(randf_range(0,.5)).timeout
			generate()

func generate() -> void:
	var brick :RigidBody2D= BRICK.instantiate()
	brick.global_position = global_position
	brick.apply_central_force(generate_force*Vector2.DOWN.rotated(rotation))
	get_parent().call_deferred("add_child", brick)
